package com.chis.dubbo.service;

import com.chis.jmdatatimer.comm.JedisConnect;
import com.chis.jmdatatimer.comm.TdJxcGpsdata;
import com.chis.jmdatatimer.comm.TxMgmtModuleMysql;
import com.chis.jmdatatimer.timerDto.dto.TimerDTO;
import com.chis.protostuff.ProtostuffSerialize;
import redis.clients.jedis.ShardedJedis;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年03月14日
 */
public class TestImpl  implements ITest {

    @Resource
    protected TimerDTO dto;

    @Override
    public void method() {

        //内存库操作
        for(int i = 0 ; i< 10 ; i++){
            redisopt();
        }

        //物理库操作
        mysqlopt();


    }

    public void redisopt(){
        Long l1 = System.currentTimeMillis();
        ShardedJedis jedis = null;
        try {
            jedis = JedisConnect.getInstance().jedisPool.getResource();
            jedis.select(15);
            jedis.set(UUID.randomUUID().toString(), "wlj");

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jedis != null) {
                jedis.close();
            }
        }
        Long l2 = System.currentTimeMillis();
        System.out.println("redis："+(l2-l1));
    }

    public void mysqlopt(){
        List<TdJxcGpsdata> list = new ArrayList<>();
        for(int i = 0 ; i < 10 ; i++){
            TdJxcGpsdata tdJxcGpsdata = new TdJxcGpsdata();
            tdJxcGpsdata.setTransCode("32010000022018110501");
            tdJxcGpsdata.setMonitTime(new Date());
            tdJxcGpsdata.setLat("1");
            tdJxcGpsdata.setLng("1");
            list.add(tdJxcGpsdata);
        }
        Long l2 = System.currentTimeMillis();
        dto.insertBatch(list);
        Long l3 = System.currentTimeMillis();
        System.out.println("mysql:"+(l3-l2));

    }


    @Override
    public TestBean test(byte[] bytes) throws Exception {
        ProtostuffSerialize serialize = new ProtostuffSerialize(TestBean.class);
        TestBean srcbean = (TestBean)serialize.deserialize(bytes);
        System.out.println(srcbean.getS1());
        System.out.println(srcbean.getS2());
        System.out.println(srcbean.getS3());
        System.out.println(srcbean.getS4());
        TestBean testBean = new TestBean();
        testBean.setS1("qqq");
        testBean.setS2("www");
        testBean.setS3("eee");
        testBean.setS4("rrr");

        return testBean;
    }

}
